pub mod const_value;

mod cadd;
mod cbuild;
mod cnew;
mod cstore;
mod ctest;
mod rtools;

use clap::{command, Parser};
use const_value::{ABOUT, AUTHOR, LONG_ABOUT, VERSION};

/// 命令行参数
#[derive(Parser, Debug)]
#[command(author = AUTHOR, version = VERSION, about = ABOUT, long_about = LONG_ABOUT)]
struct Args {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Parser, Debug)]
enum Commands {
    /// 在当前目录新建项目
    New(cnew::CommandsNew),
    /// 构建当前目录下的项目
    Build(cbuild::CommandsBuild),
    /// 保存项目为库项目并存储到仓库中
    Store(cstore::CommandsStore),
    /// 在当前项目下添加库依赖
    Add(cadd::CommandsAdd),
    /// 运行单元测试
    Test(ctest::CommandsTest),
}

fn main() -> std::io::Result<()> {
    // 解析命令行参数
    let args = Args::parse();

    match args.command {
        Commands::New(config) => cnew::run(config),
        Commands::Build(config) => cbuild::run(config),
        Commands::Store(config) => cstore::run(config),
        Commands::Add(config) => cadd::run(config),
        Commands::Test(config) => ctest::run(config),
    }?;

    Ok(())
}
